package com.zyw.mvc.bind;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

import java.text.SimpleDateFormat;

/**
 * @author vill on 2014/8/11 20:21.
 * @desc
 */
public class CustomDataBinding implements WebBindingInitializer {

    @Override
    public void initBinder(WebDataBinder binder, WebRequest webRequest) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        SimpleDateFormat datetimeFormat = new SimpleDateFormat(
                "yyyy-MM-dd");
        datetimeFormat.setLenient(false);
        binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(dateFormat, true));
        binder.registerCustomEditor(java.sql.Date.class, new CustomSqlDateEditor(datetimeFormat, true));
    }
}
